import QtQuick 2.15
import mytablemodel 1.0


Rectangle {
    id: root
    color: "#0A3653"

    property int selected:0

    //signal viewSwitched(int index)
    property bool showMainOption: false

    property int shift: !root.showMainOption ? -height : 0
    visible: shift > -height
    Behavior on shift {
        NumberAnimation {}
    }

//    Connections {
//        target: root
//        onSelectedChanged: viewSwitched(selected)
//    }

    Row {
        id: row
        anchors.fill: parent

        BottomBarButton {
            id: statusButton
            width: root.width/5
            height: root.height

            isSelected: root.selected === 0
            title: qsTr("状态")

            //Connections {
            //    target: statusButton
                onClicked: {
                    if(mainLoader.visible)
                    {
                        return;
                    }
                    //myLoader.visible=false;
                    root.selected = 0
                    //myLoader.visible=true
                    //myLoader.visible=false;
                    //dataPanel.visible=false;
                    //statusView.visible=true
                    myLoader.source="StatusView.qml"
                    //myLoader.setsourceComponent=Qt.createComponent("StatusView.qml", Component.Asynchronous, rectangle);
                }
            //}
        }

        BottomBarButton {
            id: dataButton
            width: root.width/5
            height: root.height

            isSelected: root.selected === 1
            title: qsTr("数据")

            //Connections {
            //    target: dataButton
                onClicked: {
                    if(mainLoader.visible)
                    {
                        return;
                    }
                    //myLoader.visible=false;
                    //myLoader.visible=true
                    //mainLoader.visible=true
                    root.selected = 1
                    myLoader.source="DataView.qml"
                    //dataPanel.visible=true
                    //myLoader.visible=false
                    //statusView.visible=false
                    //myLoader.setsourceComponent=dataPanel

                            //Qt.createComponent("DataView.qml", Component.Asynchronous, rectangle);
                }
            //}
        }

        BottomBarButton {
            id: functionButton
            width: root.width/5
            height: root.height

            isSelected: root.selected === 2
            title: qsTr("功能")

            //Connections {
            //    target: functionButton
                onClicked: {
//                    myLoader.visible=false;
//                    myLoader.visible=true
                    if(mainLoader.visible)
                    {
                        return;
                    }
                    myLoader.source="FunctionPanel.qml"
                    //mymodbus.getMaxRange()
                    //dataPanel.visible=false
                    //statusView.visible=false
                    root.selected = 2
                }
            //}
        }


        BottomBarButton {
            id: versionButton
            width: root.width/5
            height: root.height

            isSelected: root.selected === 3
            title: qsTr("信息")

            //Connections {
            //    target: versionButton
                onClicked: {
//                    myLoader.visible=false;
//                    myLoader.visible=true
                    //dataPanel.visible=false
                    //statusView.visible=false
                    if(mainLoader.visible)
                    {
                        return;
                    }
                    myLoader.source="VersionPanel.qml"
                    //mymodbus.getSoftwareVersion()
                    //mymodbus.getDevDate()
                    //mymodbus.getWeight()
                    root.selected = 3
                    //mymodbus.slotSwitchToGps(true);
                    //mymodbus.slotRestart4g(true);
                }
            //}
        }
        BottomBarButton {
            id: settingsButton
            width: root.width/5
            height: root.height

            isSelected: root.selected === 4
            title: qsTr("设置")

            //Connections {
            //    target: settingsButton
                onClicked: {
//                    myLoader.visible=false;
//                    myLoader.visible=true
                    //dataPanel.visible=false
                    //statusView.visible=false
                    if(mainLoader.visible)
                    {
                        return;
                    }
                    root.selected = 4
                    myLoader.source="SettingsPanel.qml"
                    //mymodbus.slotSwitchToGps(false);
                    //mymodbus.slotRestart4g(false);
                }
            //}
        }

    }
}

